package hqyj.example.provider.controller;


import hqyj.example.provider.service.GoodsService;
import hqyj.example.provider.view.Catalog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("catalog")  //这才是名空间
//获得商品类别的接口
public class CatalogController {

    @Resource
    private GoodsService goodsService;

    @GetMapping("/") //表示发送get请求，这个请求的URL地址。
    public Map<String, Object> queryAllCatalogList() {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<Catalog> catalogList = goodsService.queryAllCatalogList();
            result.put("code", 200);
            result.put("msg", "查询商品类别列表成功！");
            result.put("data", catalogList);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            result.put("code", 400);
            result.put("msg", "程序出现错误！");
            return result;
        }
    }
}
